#include "cmsis_os.h"
#include "stm32f4xx_hal.h"
#include "flash_simulate_eeprom.h"

#define xsEEPROMDemoEnable

#ifdef sEEPROMDemoEnable
osThreadId sEEPROMDemoTaskID;

void sEEPROMDemoTask(void const * argument)
{
	osEvent event; 
	uint32_t i;
	uint16_t VarValue;
	uint16_t VarDataTab[NB_OF_VAR];
	while(1)
	{

		i=0;
		while(i<10)
		{
			i++;
			for (VarValue = 0; VarValue < NB_OF_VAR; VarValue++)
			{
				if((EE_WriteVariable(VirtAddVarTab[VarValue],  VarValue+i)) != HAL_OK)
				{
					printf("EEROM Write error\r\n");
					break;
				}
			}
			for (VarValue = 0; VarValue < NB_OF_VAR; VarValue++)
			{
				if((EE_ReadVariable(VirtAddVarTab[VarValue],  &VarDataTab[VarValue])) != HAL_OK)
				{
					printf("EEROM read error\r\n");
					break;
				}
				if (VarValue+i != VarDataTab[VarValue])
				{
					printf("EEROM read value error\r\n");
					break;
				}
			}
		}
		osDelay(100);
		printf("osThreadTerminate\r\n");
		osThreadTerminate(NULL);
	}
}

void sEEPROMDemoTaskEntery(void)
{
  /* Create the timer(s) */
  /* definition and creation of myTimer01 */
  osThreadDef(sEEPROMDemo, sEEPROMDemoTask, osPriorityNormal, 0, 256);
  sEEPROMDemoTaskID = osThreadCreate(osThread(sEEPROMDemo), NULL);
}

#else
void sEEPROMDemoTaskEntery(void)
{

}
#endif
